package ch.hslu;

import java.util.ArrayList;

public class Customer {
	private String name;
	private ArrayList<Rental> rentals = new ArrayList<Rental>();

	public Customer(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void addRental(Rental rental) {
		this.rentals.add(rental);
	}

	private int getTotalFrequentRenterPoints() {
		int points = 0;
		for (Rental r : rentals) {
			points += r.getDaysRented();
		}
		return points;
	}

	private double getTotalCharge() {
		double price = 0;
		for (Rental r : rentals) {
			price += r.getCharge();
		}
		return price;
	}

	public String statement() {
		String result = "Rental Record for " + getName() + "\n";
		for (Rental r : rentals) {
			// show figures for this rental
			result += " " + r.getMovie().getTitle() + " "
					+ String.valueOf(r.getCharge()) + "\n";
		}
		// add footer lines
		result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
		result += "You earned "
				+ String.valueOf(getTotalFrequentRenterPoints())
				+ " frequent renter points";
		return result;
	}

	public String htmlStatement() {
		String result = "<H1>Rentals for <EM>" + getName() + "</EM></H1>\n";
		for (Rental r : rentals) {
			result += r.getMovie().getTitle() + ": "
					+ String.valueOf(r.getCharge()) + "<BR>\n";
		}
		// add footer lines
		result += "You owe <EM>" + String.valueOf(getTotalCharge())
				+ "</EM>\n";
		result += "On this rental you earned <EM>"
				+ String.valueOf(getTotalFrequentRenterPoints())
				+ "</EM> frequent renter points";
		return result;
	}

}
